package com.wwc.member.controller;

import com.wwc.common.response.CommonResponse;
import com.wwc.member.controller.dto.member.MemberLoginDTO;
import com.wwc.member.controller.dto.member.MemberRegisterDTO;
import com.wwc.member.controller.dto.member.MemberSendCodeDTO;
import com.wwc.member.controller.vo.MemberLoginVO;
import com.wwc.member.entity.Member;
import com.wwc.member.service.IMemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员 Controller
 */
@RestController
@RequestMapping("/member")
public class MemberController{
	@Resource
	private IMemberService memberService;

	/**
	 * 查询会员列表
	 */
	@GetMapping("/select-list")
	public CommonResponse<List<Member>> selectList(){
		List<Member> memberList = memberService.list();
		return new CommonResponse<>(memberList);
	}

	/**
	 * 统计会员总数
	 */
	@GetMapping("/count")
	public CommonResponse<Long> count(){
		Long count = memberService.count();
		return new CommonResponse<>(count);
	}

	/**
	 * 注册会员
	 */
	@PostMapping("/register")
	public CommonResponse<Long> register(@Valid @RequestBody MemberRegisterDTO memberRegisterDTO){
		Long id = memberService.register(memberRegisterDTO);
		return new CommonResponse<>(id);
	}

	/**
	 * 发送验证码
	 */
	@PostMapping("/send-code")
	public CommonResponse<?> sendCode(@Valid @RequestBody MemberSendCodeDTO memberSendCodeDTO){
		memberService.sendCode(memberSendCodeDTO);
		return new CommonResponse<>();
	}

	/**
	 * 会员登录
	 */
	@PostMapping("/login")
	public CommonResponse<MemberLoginVO> login(@Valid @RequestBody MemberLoginDTO memberLoginDTO){
		MemberLoginVO memberLoginVO = memberService.login(memberLoginDTO);
		return new CommonResponse<>(memberLoginVO);
	}
}
